$(function () {
    var picture_id = $('#pid').text();
    user_click(picture_id);
    });


//用户点赞收藏
function user_click(picture_id) {
    var parise = $('.wish');
    var star = $('.score-btn');
    var user_id = $('#user_id').text();
    parise.click(function () {
        if (user_id != -1) {
            $.get('/user/parise_star/', {'media_id': picture_id, 'user_id': user_id, 'active': 0, 'type': '1'}, function (data) {
                var jsonObj = JSON.parse(data);
                var type = jsonObj['type'];
                if (type == '1') $('#star').text(Number($('#star').text())+1);
                else $('#star').text(Number($('#star').text())-1);
            });
        }
        else {
            alert('请先登录')
        }

    });
    star.click(function () {
       if (user_id != -1) {
            var i = $(this);
            $.get('/user/parise_star/', {'media_id': picture_id, 'user_id': user_id, 'active': 1, 'type': '1'}, function (data) {
                var jsonObj = JSON.parse(data);
                var type = jsonObj['type'];
                if (type == '1') $('#parise').text(Number($('#parise').text())+1);
                else $('#parise').text(Number($('#parise').text())-1);
            });
        }
        else {
            alert('请先登录')
        }
    });

}
